package com.qxcy.gzy.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * 网络相关工具类
 * 
 * @author gzy
 * 
 */
public class NetWorkUtils {
    /**
     * 判断是否有可用网络
     * 
     * @param context
     * @return
     */
    public static boolean isNetWorkOpened(Context context) {
        ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connManager.getActiveNetworkInfo() != null) {
            return connManager.getActiveNetworkInfo().isAvailable();
        }
        return false;
    }

    /**
     * 判断是否有网络连接
     * 
     * @param context
     * @author gzy
     * @return
     */
    public static boolean isNetworkConnected(Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivityManager != null) {
            NetworkInfo mNetworkInfo = connectivityManager.getActiveNetworkInfo();
            // 判断网络连接是否打开
            if (mNetworkInfo != null && mNetworkInfo.isAvailable()) {
                return mNetworkInfo.isConnected();
            }
        }
        return false;
    }

}